Day 12 - Regular expressions - Single characters

44

Exercise 12.02

Log entries in the file simple.log contain the string HTTP/<version> <code>, where <version> is

the version of the HTTP protocol in use (either 1.0 or 1.1) and <code>“ is the three-digits

HTTP request status code. Extract all lines with a status “4xx” (that is a status between 400 and 499).

Count how often each status occurs.

Go to solution

Let’s wrap up this short (and hopefully simple enough) introduction to regular expressions. You

can already appreciate that a simple syntax like “d.” has a powerful meaning and can match many

different strings. In the exercises we were already able to create a nice and useful filter for HTTP

codes without knowing in advance which ones were contained in the file. In the next lesson we will

keep discussing regular expressions introducing new parts of their syntax.

If you head is spinning, sit, relax, have a drink (maybe a soft one, otherwise the spinning will just

get worse). It’s time for something not related to regular expressions, editors, and command lines.

What about a documentary on the history of operating systems? Just kidding! Have a walk, watch

a TV series, enjoy your day!

Suggested film for the evening: The AristoCats (1970) - There are too many dogs in this chapter, it’s

time to fix it properly.